/*
 * @Author: 赵成功a 3063126760@qq.com
 * @Date: 2024-12-26 23:34:28
 * @LastEditors: 赵成功a 3063126760@qq.com
 * @LastEditTime: 2024-12-27 02:19:35
 * @FilePath: /linux-learning/Sharedmemory/Client.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include"Init.hpp"  
int main() {  
    int shmid =GetShm();
    char* buffer = (char*) shmat(shmid, NULL, 0); // 挂接空间，用char*去访问这片空间  
    int fd=open(FIFE_PIPE,O_RDONLY);
    if(fd<0){
        log(Fatal,"client open failed,error string:%s,error code:%d",strerror(errno),errno);
        exit(OPEN_ERR);
    }

    while (true) {  
        char a;
        size_t n=read(fd,&a,1);
        if(n==1){ 
             cout << "Client receive: " << buffer ; 
        }
        if(n==0)  break;
    }  
    shmdt(buffer); // 解除联系  
    shmctl(shmid, IPC_RMID, NULL); // 删除共享内存  
    return 0;  
}  